Cute 50-line-ish game

Charlie Veniot17th March 2022 at 11:37pm
' This program based on QB64 program by "bplus" in the Basic4All forums
' http://basic4all.info8-hosting.info/index.php?topic=60.0
'
'🟠 DECLARATIONS
	Const nStars = 1000, nEnemies = 35 'b+ mod of some game
	Dim SX(nStars), SY(nStars), SC(nStars) As long : dim star_background%(475000) '🔸stars stuff
	Dim EX(nEnemies), EY(nEnemies), EC(nEnemies) As long '🔸enemy stuff
	Dim As Double HX, HY, i, hits, score
	HX = 320: HY = 400  : dim hero%(10) '🔸hero stuff (you)
'🟠 GAME SETUP
	Screen 18: gosub setup_stars : gosub setup_enemies : gosub setup_hero : gosub setup_for_start
'🟠 MAIN PROGRAM
	Do
		cls : PUT (0, 0), star_background%, pset : Print "Hits:"; hits, "Score:"; score : PUT (HX-10, HY-10), hero%, pset
		For i = 1 To nEnemies '🔸the enemies
			Circle (EX(i), EY(i)), 10, EC(i)
			If Sqr((EX(i) - HX) ^ 2 + (EY(i) - HY) ^ 2) < 20 Then '🔸collision
				Sound 2000, 3: hits = hits + 1
				EX(i) = Int(Rnd * 600 + 20): EY(i) = -480 * Rnd '🔸move that bad boy!
				If hits = 10 Then Print "Too many hits, goodbye!": End
			End If
			EY(i) = EY(i) + Int(Rnd * 5)
			If EY(i) > 470 Then EX(i) = Int(Rnd * 600 + 20): EY(i) = -480 * Rnd: score = score + 1
		Next i
		k$ = lcase$(inkey$)
		If k$ = "m" Then HY += 1 
		If k$ = "k" Then HY -= 1
		If k$ = "a" Then HX -= 1
		If k$ = "s" Then HX += 1
		If HX < 10 Then HX = 10
		If HX > 630 Then HX = 630
		If HY < 10 Then HY = 10
		If HY > 470 Then HY = 470
Loop
'🟠 SUBROUTINES
setup_stars:
	cls
	For i = 1 To nStars
		SX(i) = Int(Rnd * 640) : SY(i) = Int(Rnd * 480) : SC(i) = (55 + Rnd * 200) *  256^2 +  (55 + Rnd * 200) * 256 + (55 + Rnd * 200)
	Next i
	For i = 1 To nStars
		PSet (SX(i), SY(i)), SC(i)
	Next i
	GET (0,0)-(640,480),star_background% : cls : return
setup_enemies:
	For i = 1 To nEnemies
		EX(i) = Int(Rnd * 600 + 20) : EY(i) = -2 * 480 * Rnd + 480 : EC(i) = (55 + Rnd * 200) * 256^2 + (55 + Rnd * 200) * 256 + (55 + Rnd * 200)
	Next i
	return
setup_hero:
	cls : Line (0, 0)-(19,19), &HFFFFFF00, BF : GET (0,0)-(19,19),hero% : cls : return
setup_for_start:
	print "To move, use these keys:" : print "[A] = Left"  : print "[S] = Right"  : print "[M] = Down"  : print "[K] = Up" 
	print : print "Position your fingers on these keys, and press a key to start the game." : while inkey$ = "" : wend : return